package com.example.jobback.controller.recruiter;

import com.example.jobback.dto.PublishPositionDto;
import com.example.jobback.req.recruiter.position.publish.PublishPositionReq;
import com.example.jobback.req.recruiter.position.publish.ResubmitPublishPositionReq;
import com.example.jobback.req.recruiter.position.search.RCrossSearchJobOrCompanyReq;
import com.example.jobback.req.recruiter.position.update.RCrossChangePositionReq;
import com.example.jobback.req.recruiter.position.update.UpdatePositionReq;
import com.example.jobback.resp.manager.position.update.ManagerPendingUpdateJobResp;
import com.example.jobback.resp.recruiter.position.GetCompanyPositionResp;
import com.example.jobback.resp.recruiter.position.GetUserPositionDetailResp;
import com.example.jobback.resp.recruiter.position.GetUserPositionResp;
import com.example.jobback.resp.recruiter.position.publish.*;
import com.example.jobback.resp.recruiter.position.search.RCrossSearchJobOrCompanyResp;
import com.example.jobback.resp.recruiter.position.update.CompanyPendingUpdateJobResp;
import com.example.jobback.resp.recruiter.position.update.JobChangeInformationResp;
import com.example.jobback.resp.recruiter.position.update.UpdatePositionResp;
import com.example.jobback.result.Result;
import com.example.jobback.service.recruiter.RecruiterPositionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: RecruiterPositionController
 * @Description:招聘者-职位控制器
 * @Author: lhb
 * @Date: 2025/6/21
 */
@RestController
@RequestMapping("/recruiter/position")
@Tag(name = "招聘者-职位控制器",description = "招聘者职位服务对应的相关接口")

public class RecruiterPositionController {


    private final RecruiterPositionService recruiterPositionService;

    public RecruiterPositionController(RecruiterPositionService recruiterPositionService) {
        this.recruiterPositionService = recruiterPositionService;
    }

    @Operation(summary = "发布岗位",description = "无")
    @ApiResponse(description = "返回响应体")
    @PostMapping("/publishPosition")
    public Result<PublishPositionResp> publishPosition(@Validated
                                                       @RequestBody
                                                       PublishPositionReq req){
        return recruiterPositionService.publishPosition(req);
    }

    @Operation(summary = "取消发布岗位",description = "无")
    @ApiResponse(description = "返回删除状态")
    @DeleteMapping("/cancelPublishPosition")
    public Result<Object> cancelPublishPosition(@Parameter(description = "发布岗位的唯一标识", required = true)
                                                @RequestParam String code){
        return recruiterPositionService.cancelPublishPosition(code);
    }

    @Operation(summary = "重新提交发布的岗位",description = "无")
    @ApiResponse(description = "返回响应体")
    @PostMapping("/resubmitPublishPosition")
    public Result<ResubmitPublishPositionResp> resubmitPublishPosition(@Validated
                                                                       @RequestBody ResubmitPublishPositionReq req){
        return recruiterPositionService.resubmitPublishPosition(req);
    }

    @Operation(summary = "公司审核发布岗位不通过",description = "无")
    @ApiResponse(description = "返回token")
    @PostMapping("/companyVerifyPublishPositionFailed")
    public Result<Object> companyVerifyPublishPositionFailed(@Parameter(description = "发布岗位的唯一标识", required = true)
                                                             @RequestParam String code,
                                                             @Parameter(description = "错误反馈信息", required = true)
                                                             @RequestParam String message){
        return recruiterPositionService.companyVerifyPublishPositionFailed(code,message);
    }

    @Operation(summary = "公司审核发布岗位通过",description = "无")
    @ApiResponse(description = "返回token")
    @PostMapping("/companyVerifyPublishPosition")
    public Result<Object> companyVerifyPublishPosition(@Parameter(description = "发布岗位的唯一标识", required = true)
                                                       @RequestParam String code){
        return recruiterPositionService.companyVerifyPublishPosition(code);
    }

    @Operation(summary = "返回个人发布待审核的岗位",description = "无")
    @ApiResponse(description = "返回响应体")
    @GetMapping("/getUserPublishPositions")
    public Result<List<GetUserPublishPositionResp>> getUserPublishPositions(){
        return recruiterPositionService.getUserPublishPositions();
    }

    @Operation(summary = "返回公司发布待审核的岗位",description = "无")
    @ApiResponse(description = "返回响应体")
    @GetMapping("/getCompanyPublishPositions")
    public Result<List<GetCompanyPublishPositionResp>> getCompanyPublishPositions(){
        return recruiterPositionService.getCompanyPublishPositions();
    }

    @Operation(summary = "根据唯一标识返回个人发布待审核的岗位",description = "无")
    @ApiResponse(description = "返回响应体")
    @GetMapping("/getUserPublishPositionByCode")
    public Result<GetUserPublishPositionDetailResp> getUserPublishPositionByCode(@Parameter(description = "发布岗位的唯一标识", required = true)
                                                                           @RequestParam String code){
        return recruiterPositionService.getUserPublishPositionByCode(code);
    }

    @Operation(summary = "跨服务-注册发布岗位",description = "无",hidden = true)
    @ApiResponse(description = "返回响应体")
    @PostMapping("/registerPublishPosition")
    public Result<Object> registerPublishPosition(@RequestBody
                                                  PublishPositionDto dto){
        return recruiterPositionService.registerPublishPosition(dto);
    }

    @Operation(summary = "返回个人发布成功的岗位",description = "无")
    @ApiResponse(description = "返回响应体")
    @GetMapping("/getUserPositions")
    public Result<List<GetUserPositionResp>> getUserPositions(){
        return recruiterPositionService.getUserPositions();
    }

    @Operation(summary = "返回公司发布成功的岗位",description = "无")
    @ApiResponse(description = "返回响应体")
    @GetMapping("/getCompanyPositions")
    public Result<List<GetCompanyPositionResp>> getCompanyPositions(){
        return recruiterPositionService.getCompanyPositions();
    }

    @Operation(summary = "根据职位id查看本公司发布成功的岗位详细信息",description = "无")
    @ApiResponse(description = "返回响应体")
    @GetMapping("/getUserPositionById")
    public Result<GetUserPositionDetailResp> getUserPositionById(@Parameter(description = "职位id", required = true)
                                                           @RequestParam Long positionId){
        return recruiterPositionService.getUserPositionById(positionId);
    }

    @Operation(summary = "修改岗位信息",description = "无")
    @ApiResponse(description = "返回响应体")
    @PostMapping("/updateUserPosition")
    public Result<UpdatePositionResp> updateUserPosition(@RequestBody
                                                         UpdatePositionReq req){
        return recruiterPositionService.updateUserPosition(req);
    }

    @Operation(summary = "取消变更岗位信息",description = "无")
    @ApiResponse(description = "返回token")
    @DeleteMapping("/cancelUpdateUserPosition")
    public Result<Object> cancelUpdateUserPosition(@Parameter(description = "职位id", required = true)
                                                   @RequestParam Long positionId){
        return recruiterPositionService.cancelUpdateUserPosition(positionId);
    }

    @Operation(summary = "查看岗位变更信息",description = "无")
    @ApiResponse(description = "返回响应体")
    @GetMapping("/checkPositionChangeInformation")
    public Result<JobChangeInformationResp> checkPositionChangeInformation(@Parameter(description = "职位id", required = true)
                                                                           @RequestParam Long positionId){
        return recruiterPositionService.checkPositionChangeInformation(positionId);
    }

    @Operation(summary = "暂时停用-获取公司变更待审核岗位的列表",description = "目前为全量查询，后期改为分页查询" ,hidden = true)
    @GetMapping("/getUpdatedPositionLists")
    @ApiResponse(description = "返回变更待审核岗位的列表")
    public Result<List<CompanyPendingUpdateJobResp>> getUpdatedPositionLists(){
        return recruiterPositionService.getUpdatedPositionLists();
    }

    @Operation(summary = "公司审核岗位变更通过",description = "无")
    @ApiResponse(description = "返回token")
    @PostMapping("/companyVerifyChangePosition")
    public Result<Object> companyVerifyChangePosition(@Parameter(description = "职位id", required = true)
                                                      @RequestParam Long positionId) {
        return recruiterPositionService.companyVerifyChangePosition(positionId);
    }

    @Operation(summary = "公司审核岗位变更不通过",description = "无")
    @ApiResponse(description = "返回token")
    @PostMapping("/companyVerifyChangePositionFailed")
    public Result<Object> companyVerifyChangePositionFailed(@Parameter(description = "职位id", required = true)
                                                            @RequestParam Long positionId,
                                                            @Parameter(description = "错误反馈信息", required = true)
                                                            @RequestParam String failMessage){
        return recruiterPositionService.companyVerifyChangePositionFailed(positionId, failMessage);
    }

    @Operation(summary = "删除岗位",description = "无")
    @ApiResponse(description = "返回token")
    @DeleteMapping("/deletePosition")
    public Result<Object> deletePosition(@Parameter(description = "职位id", required = true)
                                         @RequestParam Long positionId){
        return recruiterPositionService.deletePosition(positionId);
    }

    @Operation(summary = "跨服务-变更岗位",description = "跨服务，被调用方",hidden = true)
    @ApiResponse(description = "返回变更成功状态")
    @PostMapping("/changePositionInformation")
    public Result<Object> changePositionInformation(@RequestBody
                                                    RCrossChangePositionReq req){
        return recruiterPositionService.changePositionInformation(req);
    }

    @Operation(summary = "跨服务-搜索岗位或者公司",description = "搜索岗位或者公司,跨服务，被调用方",hidden = true)
    @ApiResponse(description = "返回搜索功能响应体")
    @PostMapping("/searchJobOrCompany")
    public Result<Object> searchJobOrCompany(@RequestBody
                                                                   RCrossSearchJobOrCompanyReq req){
        return recruiterPositionService.searchJobOrCompany(req);
    }
}
